import React from 'react';
import CateList from './components/CateList'
import GoodsList from './components/GoodsList'
import sendHttp from './http/sendHttp';
import './App.css';

class App extends React.Component {
  cateRef = React.createRef();
  state = {
    list: []
  }
  render() {
    return (
      <div className='box'>
        <CateList ref={this.cateRef} getParams={(cid, sid, sort) => this.getParams(cid, sid, sort)} />
        <GoodsList list={this.state.list} />
      </div>
    )
  }
  async getParams(cid, sid, sort) {
    let priceOrder = ""
    let news = 0
    if (sort === '价格') {
      priceOrder = 'asc'
    } else if (sort === '默认') {
      priceOrder = ""
      news = 0
    } else {
      news = 1
    }
    sendHttp("get", `/api/pc/get_products?page=1&limit=10&cid=${cid}&sid=${sid}&priceOrder=${priceOrder}&news=${news}`)
    .then(({data})=>{
      let res = data
      this.setState({
        list: res.data.list
      })
    })
  }
}

export default App;
